package com.leyou.trade.web;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.leyou.trade.dto.OrderDTO;
import com.leyou.trade.dto.OrderFormDTO;
import com.leyou.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderFormDTO orderFormDTO, HttpServletRequest request){
        //状态码，返回内容
        return ResponseEntity.status(HttpStatus.CREATED).body(this.orderService.createOrder(orderFormDTO,request));
    }

    @GetMapping("{id}")
    public ResponseEntity<OrderDTO> queryOrderById(@PathVariable("id")Long orderId){

        return ResponseEntity.ok(this.orderService.queryOrderById(orderId));
    }

    /**
     * 根据订单id查询订单状态
     * @param orderId
     * @return
     */
    @GetMapping("/status/{id}")
    public ResponseEntity<Integer> queryOrderStatus(@PathVariable("id")Long orderId){

        return ResponseEntity.ok(orderService.queryPayStatus(orderId));
    }


    @GetMapping("/UpdateStatus")
    public  ResponseEntity<Void>  UpdateStatus(Long skuId){
        orderService.UpdateStatus(skuId);
        return ResponseEntity.ok().build();
    }
}
